﻿namespace Hidistro.UI.SaleSystem.CodeBehind
{
    using Hidistro.Entities.Orders;
    using Hidistro.Membership.Context;
    using Hidistro.SaleSystem.Shopping;
    using Hidistro.UI.Common.Controls;
    using System;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    [ParseChildren(true)]
    public class Index : HtmlTemplatedWebControl
    {
        protected override void AttachChildControls()
        {
            HiContext current = HiContext.Current;
            PageTitle.AddDefaultSiteNameTitle(current.SiteSettings.SiteName, HiContext.Current);
        }

        protected override void OnInit(EventArgs e)
        {
            try
            {
                string UA = HttpContext.Current.Request.UserAgent;
                Regex r1 = new Regex("AppleWebKit.*Mobile", RegexOptions.IgnoreCase);
                Regex r2 = new Regex("MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE", RegexOptions.IgnoreCase);
                if (r1.IsMatch(UA) || r2.IsMatch(UA))
                {
                    if (HttpContext.Current.Request.RawUrl.IndexOf("?type") < 0)
                    {
                        r1 = new Regex("Android|webOS|iPhone|iPod|BlackBerry", RegexOptions.IgnoreCase);
                        r2 = new Regex("iPad", RegexOptions.IgnoreCase);
                        if (r1.IsMatch(UA))
                        {
                            HttpContext.Current.Response.Redirect("/vshop/");
                        }
                        else if (r2.IsMatch(UA))
                        {

                        }
                        else
                        {
                            HttpContext.Current.Response.Redirect("/vshop/");
                        }
                    }
                }
            }
            catch
            {

            }
            if (this.SkinName == null)
            {
                this.SkinName = "Skin-index.html";
            }
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.Params["OrderId"]))
            {
                this.SearchOrder();
            }
            base.OnLoad(e);
        }

        private void SearchOrder()
        {
            string s = "[{";
            string orderId = HttpContext.Current.Request["OrderId"];
            OrderInfo orderInfo = ShoppingProcessor.GetOrderInfo(orderId);
            if (orderInfo != null)
            {
                string str3 = s;
                s = str3 + "\"OrderId\":\"" + orderInfo.OrderId + "\",\"ShippingStatus\":\"" + OrderInfo.GetOrderStatusName(orderInfo.OrderStatus) + "\",\"ShipOrderNumber\":\"" + orderInfo.ShipOrderNumber + "\",\"ShipModeName\":\"" + orderInfo.RealModeName + "\"";
            }
            s = s + "}]";
            HttpContext.Current.Response.ContentType = "text/plain";
            HttpContext.Current.Response.Write(s);
            HttpContext.Current.Response.End();
        }

        private Literal litArticleContent;

    }
}

